<template>
  <view class="overall-container">
    <view class="overall-score">{{ pageData?.last_score }}</view>
    <text class="overall-desc">总体得分</text>
    <view class="overall-wrapper">
      <view class="wrapper-title">评测结果</view>
      <view class="wrapper-table">
        <view class="table-header">
          <text class="header">句序</text>
          <text class="header">得分</text>
          <text class="header">录音</text>
          <text class="header">详情</text>
        </view>
        <view class="table-row" v-for="(item, index) in pageData?.list" :key="index">
          <view class="col">
            <view class="index">{{ index + 1 }}</view>
          </view>
          <view class="col">
            <text class="score">{{ item.score }}</text>
          </view>
          <view class="col">
            <loudspeaker class="speaker" :voice="item.user_voice" />
          </view>
          <view class="col">
            <image class="detail" src="https://rwstatic.tentons.cn/web/Lesson/images/detail.png" />
          </view>
        </view>
      </view>
      <image class="wrapper-status" src="https://rwstatic.tentons.cn/web/Lesson/images/sentence-end-status.png" />
      <view class="wrapper-tag"></view>
    </view>
    <view class="overall-line"></view>
    <button class="overall-operate">继续学习</button>
  </view>
  <CwCommon />
</template>

<script setup lang="ts">
import { onLoad, onThemeChange, onUnload } from "@dcloudio/uni-app";
import API from "@/api";
import env from "@/config/env";
import { ref } from "vue";
import loudspeaker from "@/components/loudspeaker.vue";

interface IResult {
  last_score: number;
  list: IVoice[];
}

interface IVoice {
  record_id: number;
  sentences: string;
  user_voice: string;
  score: number;
  analysis: AnyObject;
  type: number;
  is_need_report: number;
}

const pageData = ref<IResult | null>(null);

onLoad(async (option) => {
  pageData.value = (await API.analysisData({ section_id: 37, type: 3 })) as IResult;
  console.log(JSON.stringify(pageData.value));
  debugger;
});
</script>

<style scoped lang="scss">
.overall-container {
  width: 100%;
  height: 100%;
  overflow: auto;

  .overall-score {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 7.2rem;
    height: 7.2rem;
    margin: 3.5rem auto 1.4rem;
    font-size: 3rem;
    font-family: baloo;
    color: #ffffff;
    background-image: url("https://rwstatic.tentons.cn/web/Lesson/images/score-wrapper.png");
    background-size: contain;
    background-repeat: no-repeat;
  }

  .overall-desc {
    display: block;
    margin-bottom: 3.1rem;
    text-align: center;
    font-size: 2rem;
    font-family: xiaolai;
    color: $uni-text-color;
  }

  .overall-wrapper {
    position: relative;
    width: 35rem;
    margin: 1.5rem auto;
    padding-top: 2rem;
    border-image-slice: 27 27 27 27 fill;
    border-image-width: 2rem 2rem 2rem 2rem;
    border-image-outset: 0 0 0 0;
    border-image-repeat: stretch stretch;
    border-style: solid;
    border-image-source: url("https://rwstatic.tentons.cn/web/Lesson/images/sentence-wrapper.png");

    .wrapper-title {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 7.5rem;
      height: 1.8rem;
      margin: 0 auto 1.8rem;
      font-family: xiaolai;
      font-size: 1.7rem;
      color: $uni-text-color;
      background-image: url("https://rwstatic.tentons.cn/web/Lesson/images/sentence-text.png");
      background-size: contain;
      background-repeat: no-repeat;
    }

    .wrapper-table {
      padding: 0 3.2rem;
      margin-bottom: 2.8rem;

      .table-header {
        display: flex;
        justify-content: space-between;
        width: 100%;
        height: 3.4rem;
        border-bottom: 1px solid #faefde;

        .header {
          display: flex;
          justify-content: center;
          width: 4rem;
          line-height: 2.4rem;
          font-family: xiaolai;
          font-size: 1.4rem;
          color: $uni-text-color;
        }
      }

      .table-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        height: 2.7rem;
        margin-top: 1.1rem;
        margin-bottom: 1.6rem;

        .col {
          width: 4rem;
          display: flex;
          justify-content: center;

          .index {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 1.8rem;
            height: 1.8rem;
            border-radius: 50%;
            font-family: xiaolai;
            font-size: 1.4rem;
            color: $uni-text-color;
            background-color: #ffebca;
          }

          .score {
            font-family: baloo;
            font-size: 1.8rem;
            color: #bf893d;
          }

          .speaker {
            width: 3.1rem;
            height: 3.1rem;
          }

          .detail {
            width: 1.8rem;
            height: 1.8rem;
          }
        }
      }
    }

    .wrapper-status {
      display: flex;
      justify-content: center;
      width: 27.6rem;
      height: 1.6rem;
      margin: 1.2rem auto 2rem;
    }

    .wrapper-tag {
      position: absolute;
      width: 8.2rem;
      height: 8.2rem;
      top: -2.5rem;
      left: 6.5rem;
      background-image: url("https://rwstatic.tentons.cn/web/Lesson/images/sentence-tag.png");
      background-size: contain;
      background-repeat: no-repeat;
    }
  }

  .overall-line {
    height: 10rem;
  }

  .overall-operate {
    position: absolute;
    bottom: 4.7rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 12rem;
    height: 5rem;
    font-family: xiaolai;
    font-size: 1.7rem;
    border-radius: 1rem;
    color: $uni-text-color;
    border: 2px solid $uni-btn-border;
    background-color: $uni-btn-prime;
  }

  .is-hover {
    color: rgba(255, 255, 255, 0.6);
  }
}
</style>
